package org.example;

import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.service.partnerpayments.nativepay.NativePayService;
import com.wechat.pay.java.service.partnerpayments.nativepay.model.Amount;
import com.wechat.pay.java.service.partnerpayments.nativepay.model.PrepayRequest;
import com.wechat.pay.java.service.partnerpayments.nativepay.model.PrepayResponse;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author: tang
 * @Description:
 * @Date 2024/4/30 11:17
 */
@Slf4j
public class NativeServiceExample {

    /** 商户号 */
    public static String merchantId = "1593191541";
    /** 商户API私钥路径 */
    public static String privateKeyPath = "/Users/tanglonglong/idea_project/cloud-test/web-springboot/web-wx/src/main/resources/wx/apiclient_key.pem";
    /** 商户证书序列号 */
    public static String merchantSerialNumber = "73AAF1F8897D4ECE9C6A468D2621410D2BADAF2A";
    /** 商户APIV3密钥 */
    public static String apiV3Key = "77be67fe81c437f7d95e2bebd2082cb5";

    public static void main(String[] args) {
        // 微信预支付订单发起 11:24 --> 13:24
        PrepayRequest prepayRequest = new PrepayRequest();
        Amount amount = new Amount();
        amount.setTotal(10);
        prepayRequest.setAmount(amount);
        prepayRequest.setSpAppid("wx8aebb211c7179b9d");
        prepayRequest.setSpMchid("1593191541");


        // 柴米商管员工端
        prepayRequest.setSubAppid("wx5512aaadefabb7b0");
        prepayRequest.setSubMchid("1615555941");

//        prepayRequest.setSubAppid("wxd4e54c8c07b8e428");
//        prepayRequest.setSubMchid("1615555941");


        prepayRequest.setNotifyUrl("http://testuam.tiango.link");
        prepayRequest.setOutTradeNo("100100111");
        prepayRequest.setDescription("微信业务支付");

        Config config =
                new RSAAutoCertificateConfig.Builder()
                        .merchantId(merchantId)
                        // 使用 com.wechat.pay.java.core.util 中的函数从本地文件中加载商户私钥，商户私钥会用来生成请求的签名
                        .privateKeyFromPath(privateKeyPath)
                        .merchantSerialNumber(merchantSerialNumber)
                        .apiV3Key(apiV3Key)
                        .build();

        // 构建service
        NativePayService service = new NativePayService.Builder().config(config).build();
        // 调用下单方法，得到应答
        PrepayResponse response = service.prepay(prepayRequest);
        log.info("处理微信NATIVE支付结束...response:{}", response);


    }

}
